package com.css.dzj.dzjdzqs.modules.apaction.aprandomplan.service.impl;

import com.alibaba.fastjson.JSON;
import com.css.dzj.dzjdzqs.common.util.HttpClientUtil;
import com.css.dzj.dzjdzqs.modules.apaction.aprandomplan.entity.JgZtkJgxnSsjygkNdjhsjEntity;
import com.css.dzj.dzjdzqs.modules.apaction.aprandomplan.mapper.JgZtkJgxnSsjygkNdjhsjMapper;
import com.css.dzj.dzjdzqs.modules.apaction.aprandomplan.service.JgZtkJgxnSsjygkNdjhsjService;
import com.css.dzj.dzjdzqs.modules.apaction.aprandomplan.vo.ApDeptExtractInfoEntityVo;
import com.css.dzj.dzjdzqs.modules.apaction.aprecordandgain.entity.JgJgdxCdcsPlaceEntity;
import com.css.dzj.dzjdzqs.modules.apaction.aprecordandgain.mapper.JgJgdxCdcsPlaceMapper;
import com.css.dzj.dzjdzqs.modules.apaction.aprecordandgain.service.JgJgdxCdcsPlaceService;
import com.css.dzj.dzjdzqs.modules.apaction.aprecordandgain.vo.ApRecordEntityVo;
import com.css.dzj.dzjdzqs.modules.apaction.aprecordandgain.vo.ApRecordGainEntityVo;
import com.css.dzj.dzjdzqs.modules.datafromzfjg.service.JgLhjgJcdxService;
import com.querydsl.jpa.impl.JPAQueryFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class JgZtkJgxnSsjygkNdjhsjServiceImpl implements JgZtkJgxnSsjygkNdjhsjService {
    @Autowired
    private JgLhjgJcdxService jcdxService;
    @Value("${AP_URL}")
    private String apUrl;
    @Autowired
    private JPAQueryFactory jpaQueryFactory;
    @Autowired
    private JgZtkJgxnSsjygkNdjhsjMapper jgZtkJgxnSsjygkNdjhsjMapper;

    //获取来自安评备案信息数据
    @Override
    @Transactional
    public void addSsjygk()  {
        try {
            String list = HttpClientUtil.doGet(apUrl + "/apDeptExtract/queryAllUnitMsg");
            List<ApDeptExtractInfoEntityVo> results = JSON.parseArray(list, ApDeptExtractInfoEntityVo.class);
            for (ApDeptExtractInfoEntityVo result : results) {
                JgZtkJgxnSsjygkNdjhsjEntity jgZtkJgxnSsjygkNdjhsjEntity = new JgZtkJgxnSsjygkNdjhsjEntity();
                jgZtkJgxnSsjygkNdjhsjEntity.setPlanId(result.getId());
                jgZtkJgxnSsjygkNdjhsjEntity.setPlanName(result.getTaskTitle());
                //TODO 时间截取成年份
                jgZtkJgxnSsjygkNdjhsjEntity.setYear(result.getCreatePerson());
                jgZtkJgxnSsjygkNdjhsjEntity.setAreaName(result.getCreatePersonLocation());
                //TODO 查询地区编码
                jgZtkJgxnSsjygkNdjhsjEntity.setAreaNumber("");
                jgZtkJgxnSsjygkNdjhsjEntity.setSuperviseDept(result.getCreatePersonUnit());
                //TODO 需求未确认
                jgZtkJgxnSsjygkNdjhsjEntity.setSampleInspectionRatio("");
                jgZtkJgxnSsjygkNdjhsjMapper.save(jgZtkJgxnSsjygkNdjhsjEntity);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
